var app = getApp()
Page({
  data: {
    arraydetail: [],
    arrayexist: [],
    windowWidth: 375,
    windowHeight: 571,
    scrollTop: 0,
    scrollHeight: 0,
    leveId: 1,
    pageIndex: 1,
    pageSize:10,
    myfans:0,
    author: 'Lotus'
  },
  swichNav: function (e) {//点击tab切换 
    var that = this;
    that.setData({
      leveId: e.target.dataset.id,
      arraydetail:[],
      pageIndex: 1
    })
    that.getmyfans();
  },
  scroll: function (event) {
    console.log("scroll start");
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },  
  getmoredata: function () {
    console.log("getmoredata start" );
    this.getmyfans();
  },
  getmyfans: function () {
    var that = this;
    var service = 'User.getInvitationList';
    var pageIndex = that.data.pageIndex;
    var pageSize = that.data.pageSize;
    var leveId = that.data.leveId;
    var arraydetail = that.data.arraydetail;
    var arrayexist = that.data.arrayexist;

    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, leveId: leveId, pageIndex: pageIndex, pageSize: pageSize },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        if (!res.data.data.code) {
 
          var dataresult = res.data.data.list.list;
          for (var i in dataresult) {     
            if (!arrayexist[dataresult[i].userId]) {
              arraydetail.push(dataresult[i]);
              arrayexist[dataresult[i].userId] = 1;
            }          
          }
          pageIndex++;
          that.setData({
            arraydetail: arraydetail,
            pageIndex: pageIndex,
            arrayexist: arrayexist,
            loadding: true
          })

        }
      }
    })

  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode = options.fromInviteCode;
    }
    app.appstart();
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          scrollHeight: res.windowHeight
        });
      }
    });
    that.getmyfans();
  }

})